<template>
  <div class="login-container">
    <!-- <particles-js ref="particlesJs" class="lizi" /> -->
    <div class="urlArrDiv">
      <!-- 配置接口地址  开发展示 -->
      <el-select
        v-if="environment === 'development'"
        placeholder="接口地址"
        :value="url"
        @change="changeAxiosUrl"
      >
        <el-option
          v-for="(item, index) in baseUrlArr"
          :key="index"
          :label="item.label"
          :value="item"
        />
      </el-select>
    </div>

   
      <div class="background">
        <div class="login-block">
          <div class="top-logo">
            <img src="../../assets/logo_images/logov1.png" class="logo" alt="" />
            <span class="title" >{{loginForm.com}}</span>
          </div>
        
          <p class="login-title" style="margin-top: -150px;">下午好，欢迎登录</p>

          <el-form ref="loginForm" class="loginForm" :model="loginForm" :rules="rules" label-width="0" size="mini">
          <!-- <el-form-item prop="account">
            <el-input v-model="loginForm.com" prefix-icon="el-icon-s-home" placeholder />
          </el-form-item> -->
          <el-form-item prop="account">
            <el-input v-model="loginForm.account"  prefix-icon="el-icon-user" placeholder="账号" @blur="blurChange" />
          </el-form-item>
          <el-form-item prop="password">
            <el-input v-model="loginForm.password" prefix-icon="el-icon-lock" type="password" show-password placeholder="密码" @keyup.enter.native="submitLogin" />
          </el-form-item>
        </el-form>
        <el-row class="login_submit_box">
          <el-button type="primary" class="login_submit" :loading="loading" @click="submitLogin">登录</el-button>
        </el-row>
        </div>
      </div>
  
    </div>
  </div>
</template>
<script>
import particlesJs from "@/components/ParticlesJs";
export default {
  components: { particlesJs },
  data() {
    const validateUsername = (rule, value, callback) => {
      if (!this.loginForm.account) {
        callback(new Error("用户名不能为空！"));
      } else {
        callback();
      }
    };
    const validatePassword = (rule, value, callback) => {
      if (!this.loginForm.password) {
        callback(new Error("密码不能为空！"));
      } else {
        callback();
      }
    };
    return {
      loginForm: {
        com: "",
        account: "kfc",
        password: "123456",
        grantType: "password",
      },
      rules: {
        account: [
          { required: true, trigger: "blur", validator: validateUsername },
        ],
        password: [
          { required: true, trigger: "blur", validator: validatePassword },
        ],
      },
      loading: false,
      baseUrlArr: [
        {
          value: "http://192.168.0.102:8001/api",
          label: "dmf:8001",
          username: "kfc",
          password: "123456",
        },
        {
          value: "http://172.16.1.180:8001",
          label: "xyr:180",
          username: "kfc",
          password: "123456",
        },
      ],
      environment: process.env.NODE_ENV,
      url: "",
    };
  },
  computed: {},
  created() {},
  mounted() {},
  methods: {
    async blurChange() {
      const res = await this.$axios.get(
        `/dobo-auth/comp?account=${this.loginForm.account}`
      );
      if (res.data.code === 200) {
        this.loginForm.com = res.data.data;
      }
    },
    submitLogin() {
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          this.loading = true;
          this.$store
            .dispatch("user/login", this.loginForm)
            .then(async (res) => {
              // this.$notify.success('登陆成功！')
              this.$router.push(
                res.adminType === 2 ? "/companyInformation" : "/"
              );
              this.loading = false;
            })
            .catch(() => {
              this.loading = false;
            });
        } else {
          return false;
        }
      });
    },
    changeAxiosUrl(row) {
      const { username, password } = row;
      this.loginForm.account = username;
      this.loginForm.password = password;
      this.$axios.defaults.baseURL = row.value;
      sessionStorage.setItem("baseURL", row.value);
    },
  },
};
</script>

<style lang="scss" scoped>
/* 动画 */
@keyframes bg {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}

@keyframes login {
  0% {
    opacity: 0;
    transform: translateX(100%);
  }

  100% {
    opacity: 1;
    transform: translateX(0%);
  }
}

.login-container {
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: relative;
}

/* 背景 */
.background {
  display: flex;
  flex-direction: row-reverse;
  /* 根据图片需求可以修改表单所处位置 */
  width: 100%;
  height: 100vh;
  background: url("../../assets/images/loginv1.png") no-repeat center;
  background-size: cover;

  animation: bg 0.5s;
}

.top-logo {
  position: absolute;
  top: 32px;
  right: 32px;
  display: flex;
  align-items: center;
  z-index: 1;
}

/* 标题 */
.title {
  margin: 10px;
  font-size: 18px;
  letter-spacing: 3px;
  text-decoration: none;
  color: white;
  font-weight: bold;
}

/* logo */
.logo {
  margin-left: 8px; /* 可根据需要调整间距 */
  width: 28px;
}

/* 登录表单域 */
.login-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 600px;
  height: 100%;
  background: rgba(95, 169, 244, 0.031);
  backdrop-filter: blur(15px);

  animation: login 1.2s;
}

.login-block .login-title {
  font-size: 32px;
  color: white;
}


.login_submit_box {
  padding: 0 60px;
  button {
  background-color: rgb(43, 122, 232);
  width: 300px;
  height: 40px;
  padding: 12px;
  font-size: 16px;
  text-align: center;
  text-transform: uppercase;
  transition: 0.5s;
  color: white;
  border: none;
  display: block;
  cursor: pointer;
  margin-top: 5px;
  border-radius: 25px;
    &:hover {
      filter: drop-shadow(0 0 20px #26739b);
      transition: all 0.5s;
      opacity: 0.5;
    }
  }
  .el-button.is-loading:before {
    background: none;
  }
}
</style>

<style lang="scss">
.loginForm {
  padding:  0 33px 0 33px;
  .el-input {
    .el-input__prefix {
      font-size: 20px;
      padding-left: 14px;
      color: #818283;
     
    }
    .el-input__inner {
      background: none;
      background-color: #fff !important;
      border-radius: 25px;
      border: 1px solid #4babe3;
      padding-left: 50px;
      color: #333333 !important;
      font-size: 17px;
      height: 45px; 
      width:300px;
    }
  }
}
</style>
